<%= render :file => 'users/_level2_nav_bar.html', :locals => { :item => :home} %>
<% content_for :css do %>
  <%= stylesheet_link_tag 'users_show','users_show_weather_forecast_portalet','users_show_site_heart_beat_portalet','users_show_favorite_search_portalet','users_show_open_api_portalet','users_show_number_location_portalet','users_show_flash_portalet','users_show_web_fetion_portalet','users_show_zhui_tian_ya_portalet' %>
<% end %>
<% content_for :javascript do %>
  <script type="text/javascript" charset="utf-8">    
    function hl(portalet_id)
    {
      ll();
      $('portalet_' + portalet_id).className = 'h_p portalet';
    }
    
    function ll()
    {
      $$('div.portalet').each(function(portalet){
        portalet.className = 'portalet';
      });
    }
    
    function update_portalets_layout()
    {
      <%= remote_function :url => update_portalets_layout_user_url(current_user_id),
            :with => "'&' +Sortable.serialize('left_portalets') + '&' + Sortable.serialize('mid_portalets') + '&' + Sortable.serialize('right_portalets')",
            :loading => 'unsortable()',
            :method => :put
       %>      
    }
    
    function sortable()
    {      
      //titleObj.setStyle({
      //  backgroundColor:'#FF6600'
      //});
      Sortable.create('left_portalets',
      {
        tag: 'div',
        only: 'portalet', 
        overlap: 'vertical', 
        constraint: false,
        dropOnEmpty:true,
        containment:['left_portalets','mid_portalets','right_portalets'],
        onUpdate: function(one) {
          update_portalets_layout();
        }
      });
      Sortable.create('mid_portalets',
      {
        tag: 'div',
        only: 'portalet', 
        overlap: 'vertical', 
        constraint: false,
        dropOnEmpty:true,
        containment:['left_portalets','mid_portalets','right_portalets'],
        onUpdate: function(one) {
          update_portalets_layout();
        }
      });
      Sortable.create('right_portalets',
      {
        tag: 'div',
        only: 'portalet', 
        overlap: 'vertical', 
        constraint: false,
        dropOnEmpty:true,
        containment:['left_portalets','mid_portalets','right_portalets'],
        onUpdate: function(one) {
          update_portalets_layout();
        }
      });
    }
    
    function unsortable()
    {
      Sortable.destroy('left_portalets');
      Sortable.destroy('mid_portalets');
      Sortable.destroy('right_portalets');
    }

    function next_hot_post() 
    {
      var current = null;
      var next_no_hidden = null;
      clear_debug();      
      $$('div#tian_ya_hot_posts div.hot_post').each(function(hot_post) {
        debug(hot_post.innerHTML + " is " + hot_post.style.display);
        if(next_no_hidden == null ) {
          if(current != null) {
            next_no_hidden = hot_post;
          } else if(hot_post.style.display == '') {          
            current = hot_post;          
            hot_post.hide();
          }                  
        }        
      });
      if(next_no_hidden == null) {
        debug('显示第一个');
        next_no_hidden = $('hot_post_<%= @hot_posts.first.id %>');
      }
      Effect.Appear(next_no_hidden);
    }
  </script>
<% end %>
<div class='left'>
  <div id="broadcast">
    <div class='head'>
      天涯热帖：
    </div>
    <div id='tian_ya_hot_posts' class='hot_posts'>
      <% @hot_posts.each_with_index do |hot_post,index| %>
      <div id="hot_post_<%= hot_post.id %>" class='hot_post' style='<%= index == 0 ? '' : 'display:none' %>'>
        <%= link_to "<b>『#{hot_post.hot_post_type.name}』</b>#{truncate hot_post.title, :length => 40}", tools_zhui_tian_ya_hot_post_url(hot_post), :target => :_blank, :title => "『#{hot_post.hot_post_type.name}』#{hot_post.title}" %>
        <%= link_to "更多...", tools_zhui_tian_ya_hot_posts_url, :title => '更多天涯热帖等着您去追', :target => :_blank, :class => :more %>
        <%#= link_to_function 'test','next_hot_post()' %>
      </div>    
      <% end %>
    </div>
  </div>
  <div id="current_user">
    <div id="user_logo" onmouseover="$('change_logo').show()" onmouseout="$('change_logo').hide()">
      <div class='logo'>
        <%= user_logo_image_tag @user,:width => 100 %>  
      </div>
      <div id='change_logo' style='display:none'>
        <%= link_to_new_or_edit_current_user_logo %>
      </div>
    </div>
    <div class="info">
      <div class='name'>
        <%= @user.nick_name %><%= link_to '✎', edit_user_url(@user), :title => '修改' if @user.current? %>        
      </div>
      <% if @user.current? %>
      <div class='stat'>
        <dl>
          <dt>手机：</dt>
          <dd>                        
            <% if @user.mobile.blank? %>
              <%= link_to '尚未绑定手机，将无法收到短信，赶紧！', edit_user_url(:id => @user.id, :target => :mobile), :title => '不绑定手机，将无法收到短信哦',:class => :alert %>
            <% else %>
              <% if current_user.fetion_version.lite? %>
                <% if current_user.lite_fetion_status.wait? %>
                <%= link_to "等待您的绑定回复中...", edit_user_url(:id => @user.id, :target => :mobile) , 
                      :title => "尚未收到您同意加飞信机器人【#{current_user.fetion.name}-#{current_user.fetion.mobile}】的确认消息哦，再试试？",
                      :class => :alert %>
                <% else %>
                <%= @user.mobile %><%= link_to '✎', edit_user_url(:id => @user.id, :target => :mobile), :title => '修改' %>
                <% end %>
              <% else %>
              <%= link_to '接口升级，请重新绑定飞信：）', edit_user_url(:id => @user.id, :target => :mobile), :title => '由于移动与2010年11月20日对旧版本的飞信（2008）进行了限制，麦吐司无法将短信发送到您手机。麦吐司及时对飞信接口进行了升级，需要您重新绑定，绑定过程不在需要您提供飞信密码了，赶快把：）', :class => :alert %>
              <% end %>
            <% end %>
          </dd>
        </dl>
      </div>
      <div class='stat'>
        <dl>
          <dt>邮箱：</dt>
          <dd>
            <%= @user.email %><%= link_to '✎', edit_user_url(@user), :title => '修改' if @user.current? %>   
          </dd>
        </dl>
      </div>
      <% end %>      
       <div class='stat'>
        <dl>
          <dt>最近一次登录于：</dt>
          <dd>
            <%= time_ago_in_words @user.login_at, false %>前
            <% if @user.current? %>
            <small>(不是您登录的？ 赶紧<%= link_to '改密码', edit_user_url(@user) %>)</small>
            <% end %>
          </dd>
        </dl>
      </div>
      <div class='h stat'>
        <dl>
          <dt>正享用的吐司：</dt>
          <dd><%= @user.user_tool_settings_count %></dd>
        </dl>
        <dl>
          <dt>已收到短信<b>(<%= @user.sms_count %>)</b></dt>
          <dd></dd>
        </dl>
        <dl>
          <dt>已收到邮件<b>(<%= @user.emails_count %>)</b></dt>
          <dd></dd>
        </dl>
        <dl class='money'>
          <dt>我的麦粒<b>(<%= @user.money %>)</b><%= link_to '如何赚取更多麦粒?',money_url(current_user), :title => '如何赚取更多麦粒?', :target => :_blank, :class => :help %></dt>
          <dd></dd>
        </dl>
      </div>
    </div>
  </div>
  <div id="portalets">
    <div id='left_portalets' class='portalets'>
    <% @left_settings.each do |setting| %>
      <%= render :file => 'users/_portalet_in_show.html', :locals => { :setting => setting} %>
    <% end %>
    </div>
    <div id='mid_portalets' class='portalets'>
    <% @mid_settings.each do |setting| %>
      <%= render :file => 'users/_portalet_in_show.html', :locals => { :setting => setting} %>
    <% end %>
    </div>
  </div>
</div>
<div class='right'>
  <div id="right_portalets" class='portalets'>
  <% @right_settings.each do |setting| %>
    <%= render :file => 'users/_portalet_in_show.html', :locals => { :setting => setting} %>
  <% end %>
  </div>
  <script type="text/javascript" charset="utf-8">    
  </script>
</div>
<div id='tmp'></div>
<script type="text/javascript" charset="utf-8">
  setInterval('next_hot_post()',10000);
</script>